#include<bits/stdc++.h>
using namespace std;
int read(){
    int f=1,x=0;
    char c;
    while (c=getchar()){
        if (c>='0'&&c<='9') x=x*10+c-'0';
        else if (c=='-') f=-1;
        else break;
    }
    return x*f;
}
int T,ans=INT_MAX;
int n,m,L,V;
int d[100005],v[100005],a[100005],p[100005],tmp[100005];
set<int>t[100005],sss;
void dfs(int deep,int cnt,int sum){
    if (deep>m){
        if (sss.size()==sum)
            ans=min(ans,cnt);
        return;
    }
    if (cnt>=ans) return;
    dfs(deep+1,cnt,sum);
    set<int>tp;
    tp=sss;
    for (auto &i:t[deep])
        sss.insert(i);
    dfs(deep+1,cnt+1,sum);
    sss=tp;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    T=read();
    while(T--){
        int cnt=0,s=0;
        n=read(),m=read(),L=read(),V=read();
        for (int i=1;i<=n;i++){
            d[i]=read(),v[i]=read(),a[i]=read();
            if (a[i]>=0) cnt++;
        }
        for (int i=1;i<=m;i++) p[i]=read();
        sort(p+1,p+1+m);
        for (int i=1;i<=n;i++){
            int b,e;
            bool f=1;
            if (a[i]>0){
                if (v[i]>V)
                    b=d[i],e=L+1;
                else if (v[i]<V)
                    b=d[i]+(V*V-v[i]*v[i])/(2*a[i])+1,e=L+1;
                else
                    b=d[i]+1,e=L+1;
            }else if (a[i]==0){
                if (v[i]>V)
                    b=d[i],e=L+1;
                else
                    f=0;
            }else{
                if (v[i]>V)
                    b=d[i],e=d[i]+(V*V-v[i]*v[i])/(2*a[i])+1;
                else
                    f=0;
            }
            //cout<<'\n'<<b<<' '<<e<<' ';
            if (f){
                bool q=0;
                for (int j=1;j<=m;j++){
                    if (p[j]>=b&&p[j]<e){
                        q=1;
                        t[j].insert(i);
                    }
                }
                //cout<<q<<'\n';
                if (q) s++;
            }
        }
        cout<<s<<' ';
        if (cnt==n) ans=1;
        else dfs(1,0,s);
        cout<<m-ans<<'\n';
        for (int i=1;i<=100000;i++) t[i].clear();
        ans=INT_MAX;
    }
    return 0;
}
